package com.ruoyi.project.WebMoudle.wxOrder.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.WebMoudle.ShopSuser.domain.ShopSuser;
import com.ruoyi.project.WebMoudle.ShopSuser.service.IShopSuserService;
import com.ruoyi.project.WebMoudle.wxOrder.domain.MoneySum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.wxOrder.domain.WxOrder;
import com.ruoyi.project.WebMoudle.wxOrder.service.IWxOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 微信订单Controller
 * 
 * @author ruoyi
 * @date 2020-07-09
 */
@Controller
@RequestMapping("/wxOrder/wxOrder")
public class WxOrderController extends BaseController
{
    private String prefix = "wxOrder/wxOrder";

    @Autowired
    private IWxOrderService wxOrderService;
    @Autowired
    private IShopSuserService shopSuserService;

    @RequiresPermissions("wxOrder:wxOrder:view")
    @GetMapping()
    public String wxOrder()
    {
        return prefix + "/wxOrder";
    }


    /**
     * 查询微信订单列表
     */
    @RequiresPermissions("wxOrder:wxOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxOrder wxOrder)
    {
        startPage();
        List<WxOrder> list = wxOrderService.selectWxOrderList(wxOrder);
        MoneySum  moneySum =wxOrderService.queryMoneySum(wxOrder);
       if (!StringUtils.isNotNull(moneySum)){
           moneySum = new MoneySum();
       }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        rspData.setMoneySum(moneySum);
        return rspData;
    }

    /**
     * 导出微信订单列表
     */
    @RequiresPermissions("wxOrder:wxOrder:export")
    @Log(title = "微信订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxOrder wxOrder)
    {
        List<WxOrder> list = wxOrderService.selectWxOrderList(wxOrder);
        ExcelUtil<WxOrder> util = new ExcelUtil<WxOrder>(WxOrder.class);
        return util.exportExcel(list, "wxOrder");
    }

    /**
     * 新增微信订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微信订单
     */
    @RequiresPermissions("wxOrder:wxOrder:add")
    @Log(title = "微信订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxOrder wxOrder)
    {
        return toAjax(wxOrderService.insertWxOrder(wxOrder));
    }

    /**
     * 修改微信订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxOrder wxOrder = wxOrderService.selectWxOrderById(id);
        mmap.put("wxOrder", wxOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存微信订单
     */
    @RequiresPermissions("wxOrder:wxOrder:edit")
    @Log(title = "微信订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxOrder wxOrder)
    {
        return toAjax(wxOrderService.updateWxOrder(wxOrder));
    }

    /**
     * 删除微信订单
     */
    @RequiresPermissions("wxOrder:wxOrder:remove")
    @Log(title = "微信订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxOrderService.deleteWxOrderByIds(ids));
    }
}
